import { Component, OnInit } from '@angular/core';
import { NetService } from '../../core/services/net-service/net.service';
import {Router} from '@angular/router'
import { ActivatedRoute, Params } from '@angular/router'
import { WebApi } from 'src/app/core/config/webapi_mapping';
import News from 'src/app/model/News';

@Component({
  selector: 'app-article',
  templateUrl: './article.component.html',
  styleUrls: ['./article.component.css']
})
export class ArticleComponent implements OnInit {

  constructor(private netService: NetService, private router:Router, private activatedRoute: ActivatedRoute) {}

  isHidden: boolean = true

  articleId: string = ''

  article: News;

  ngOnInit(): void {
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      this.articleId = params['id'];
      this.getContent(this.articleId)
    });
  }

  async getContent(id: string) {
    const result = await this.netService.getAsync(WebApi.news.getNewsById + '?id=' + id)
    if (result.state === '0') {
      this.article = result.data
      this.isHidden = false
    }
  }

}
